package com.sopt.eat.vo;

import java.util.ArrayList;

import android.os.Parcel;
import android.os.Parcelable;

public class SearchResults extends ArrayList<SearchItem> implements Parcelable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public SearchResults() {
		
	}
	
	public SearchResults(Parcel in){
		readFromParcel(in);
	}
	
	 @SuppressWarnings("unchecked")
	public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 
         public SearchResults createFromParcel(Parcel in) { 
              return new SearchResults(in); 
         } 

         public Object[] newArray(int arg0) { 
              return null; 
         } 

    };

	private void readFromParcel(Parcel in) {
		this.clear();
		
		int size = in.readInt();
		
		for(int i = 0; i < size; i++){
			SearchItem curItem = new SearchItem();
			curItem.setTitle(in.readString());
			curItem.setLatitude(in.readDouble());
			curItem.setLongitude(in.readDouble());
			curItem.setPhonenumber(in.readString());
			curItem.setAddress(in.readString());
			curItem.setDistance(in.readFloat());
			this.add(curItem);
		}
	}

	public int describeContents() {
		return 0;
	}

	public void writeToParcel(Parcel dest, int flags) {
		int size = this.size(); 
        //We have to write the list size, we need him recreating the list 
        dest.writeInt(size); 
        //We decided arbitrarily to write first the Name and later the Phone Number. 
        for (int i = 0; i < size; i++) { 
        	SearchItem curItem = this.get(i);
        	dest.writeString(curItem.getTitle());
        	dest.writeDouble(curItem.getLatitude());
        	dest.writeDouble(curItem.getLongitude());
        	dest.writeString(curItem.getPhonenumber());
        	dest.writeString(curItem.getAddress());
        	dest.writeFloat(curItem.getDistance());
        } 
	}
	
}
